package com.hc.demo.mapper;

import com.hc.demo.domain.Orders;
import com.hc.demo.dto.CalendarResponseDto;
import com.hc.demo.dto.OrdersMapperDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrdersMapper {

    /**
     * 根据userId和OrderDate查询订单，看当天有没有预约
     * @param orders
     * @return
     */
    @Select("select  orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} and orderDate=#{orderDate}")
    List<Orders> selectByUserIdAndOrderDate(Orders orders);

    @Select("select  orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} order by orderDate desc")
    List<Orders> selectByUserId(String userId);

    @Select("select  orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} and state=#{state} order by orderDate desc")
    List<Orders> selectByUserIdAndState(Orders orders);


    int selectAlreadyAppointmentNumber(Orders oders);



    // 使用useGeneratedKeys返回自增主键
    @Insert("INSERT INTO orders(orderId,userId,hpId,smId,state,orderDate) " +
            "VALUES(#{orderId}, #{userId}, #{hpId},#{smId}, #{state}, #{orderDate})")
    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    int insertOrder(Orders order);


    int deleteByPrimaryKey(Integer orderId);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(Integer orderId);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

    //如何查询某天某个医院已经约号的数量： 2025年8月25号  医院编号是1  订单有3个  200-3=197
    int selectAppointmentCountByhpidByDate(Orders orders);

    List<CalendarResponseDto> listOrdersAppointmentNumber(List<OrdersMapperDto> parameList);
}